<?php

/*

  Action	$2

  Trash up to 4 cards from your hand.

 */

class Chapel extends Card implements iAction, iKingdom, iBasic {

    private $trashedCards = array();

    public function __construct() {
        parent::__construct("Chapel", 2);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            " Trash up to 4 cards from your hand.");
    }

    public function play(Game $game, $isRealCard) {

        $cards = $game->getPlayHand();
        if (sizeof($cards) > 0) {

            $output = MySocket::GetUserReply($game, Input_ChooseMany, $cards, 0, 4, null, "Choose cards to trash");

            foreach ($output as $p) {
                $card = $game->moveCardFromPileToPile($p, PlayHand, Trash);
                $this->trashedCards[] = $card->getValue();
            }

            ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($output), "trashes " . ScreenDisplay::$LMSG);
        }

        $game->cardActionFinished();
        return true;
    }

    public function undoParamsPlay($undoParams) {
        $undoParams['trashedCards'] = $this->trashedCards;
        return array($this->undoPlay, $undoParams);
    }

    public function undo(Game $game, $undoParams) {
        $trashed_cards = $undoParams['trashedCards'];
        foreach ($trashed_cards as $tc) {
            $tc = $game->undo_func_moveCardFromPileToPile($tc, Trash, PlayHand);
        }
        //ScreenDisplay::addScreenMessage($game, true, "undo ".  nicePrint($this)." and return " . nicePrint($trashed_cards) . " to your hand", "undos ".  nicePrint($this)." and returns " . nicePrint($trashed_cards) . " to his hand");
    }

}

?>